﻿// CaptInterface.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "BaseInc.h"
#include "SDL2/SDL_video.h"
#include <chrono>
#include "MP4Output.h"
#include "UdpIPC.h"
#include <functional>
using namespace chrono;

int main(int arg, char* argv[])
{
 //   SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
 //   SDL_Window* window = SDL_CreateWindow("Player", 200, 200, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
 //   SDL_Surface* screen = SDL_GetWindowSurface(window); //SDL_GetWindowSurface(window);
 //   SDL_Renderer* render = SDL_CreateRenderer(window, 0, 0);
 //   SDL_Texture* pTex;
 //   pTex = SDL_CreateTexture(render, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, 640,480);
	//SDL_Rect rect;
	////
	//SDL_Event event;

 //   unsigned char* pixels;
 //   int pitch;

 //   while (true)
 //   {
 //       SDL_WaitEvent(&event);
 //       SDL_LockTexture(pTex, NULL, (void**)&pixels, &pitch);


 //   }
	bool IsPause = false;
	bool isRunning = false;
	std::function<void(bool)> UpdateRunningState = [&isRunning](bool b)->void {
		isRunning = b;
		};
	std::function<void(bool)> UpdatePauseState = [&IsPause](bool b)->void {
		IsPause = b;
		};

	av_register_all();
	avdevice_register_all();
	//初始化网络库
	avformat_network_init();
	UdpIPC udpIPC;
	udpIPC.Init(20312);
	//udpIPC.udp.OnReceive();
	MP4Output mp4;
	time_point<steady_clock> begin = steady_clock::now();
	time_point<steady_clock> now = steady_clock::now();
	mp4.Init();
	//int recSecondsCount = 10;
	//mp4.SetRunning(true);
	mp4.Task();
	while (!isRunning)
	{
		mp4.Update();
		now = steady_clock::now();
		int sec  = duration_cast<chrono::seconds>(now - begin).count();
	}
	mp4.FinishTask();
	//::Sleep(1000);
	//mp4.Release();
	udpIPC.Close();

    return 0;
}

